<template>
   
    <section class="mk-add-pop">
      <el-form ref="formAdd" :model="form" :rules="rules" label-width="100px">
         
      
       <mk-get-row>
          <el-form-item label="技能" prop="name">
            <el-input v-model="form.name" size="mini"
                      type="textarea"
                      :rows="3"
                     style="width: 450px"
                      clearable placeholder="技能"></el-input>
          </el-form-item>
        </mk-get-row>
        <mk-get-row v-if="form.type == 1">
          <el-form-item label="排序" prop="index">
             <el-input-number v-model="form.index" :precision="0" :step="1" :max="20" :min="1"></el-input-number>
          </el-form-item>
        </mk-get-row>
         <mk-get-row>
          <el-form-item label="是否有效" prop="type">
           
            <el-radio-group v-model="form.show" size="mini" >
                <el-radio :label="1" border>是</el-radio>
                <el-radio :label="0" border>否</el-radio>
            </el-radio-group>
          </el-form-item>
        </mk-get-row>
        <el-divider/>
        <mk-get-button @save="save" @close="close(true)"/>
      </el-form>
    </section>
</template>

<script>
import MkGetRow from "@/components/common/mk-get-row";
import MkGetButton from "@/components/common/mk-get-button";
import MkBackList from "@/components/common/mk-back-list";
import {skillCreate, skillUpdate} from "@/api/modules/sys.personal.skill.api";

export default {
  name: "get-skill-info",
  components: {MkBackList, MkGetButton, MkGetRow},
  props: {
    updateData: {
      type: Object,
      default() {
        return {};
      }
    },
  },
  created() {
    console.log(this.updateData)
    if (this.updateData && this.updateData.id) {
      this.form = this.updateData
      this.isAdd = false
    }
  },
  data() {
    return {
        commonKey: 0,
   
        form: {
            type: 1,
            show:1
      },
      isAdd: true,
        rules: {
         name: [{ required: true, message: '请输入技能', trigger: 'blur' },],
        index: [{ required: true, message: '请选择排序', trigger: 'blur' },],
        show: [{ required: true, message: '请选择是否有效', trigger: 'blur' },],
        
      }
    }
  },
  methods: {
    save() {
      this.$refs['formAdd'].validate((valid) => {
        if (valid) {
          let _FUC = ''
            _FUC = this.isAdd ? skillCreate : skillUpdate
          let msg = this.isAdd ? '添加成功！' : '修改成功！'
          _FUC(this.form).then(res => {
            this.$toast.success(msg)
            this.$emit('close',true);
          }).catch(err => {
            console.log(err)
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    close(show) {
      this.$emit('close');
     
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
